package com.smartshopping.model;

import java.util.ArrayList;
import java.util.List;

import android.os.Parcelable;

public class BillItem {
	private int BillId = 0;
	private ArrayList<Item> list;
	private int coopId;
	private int marketId;
	
	public BillItem(int billId, ArrayList<Parcelable> arrayList, int coopId, int marketId) {
		super();
		this.BillId = billId;
		this.list = createListItemFromParcelable(arrayList);
		this.coopId = coopId;
		this.marketId = marketId;
	}
	
	public BillItem(ArrayList<Item> arrayList, int coopId, int marketId, int billId ) {
		super();
		this.BillId = billId;
		this.list = arrayList;
		this.coopId = coopId;
		this.marketId = marketId;
	}
	
	public BillItem(ArrayList<Parcelable> arrayList, int coopId, int marketId) {
		super();
		this.list = createListItemFromParcelable(arrayList);
		this.coopId = coopId;
		this.marketId = marketId;
	}
	
	//convert from ArrayList<Parcelable> to ArrayList<Item>
	public ArrayList<Item> createListItemFromParcelable(ArrayList<Parcelable> arrayList)
	{
		ArrayList<Item> curList = new ArrayList<Item>();
		for (int i = 0; i < arrayList.size(); i++)
			curList.add((Item)arrayList.get(i));
		return curList;
	}
	
	public void deleteItemNotBuy()
	{
		int in = 0;
		while (in < list.size())
		{
			if (list.get(in).getAmount() > 0)
				in++;
			else
				list.remove(in);
		}
			
	}
	
	public int getBillId() {
		return BillId;
	}

	public ArrayList<Item> getList() {
		return list;
	}

	public int getCoopId() {
		return coopId;
	}

	public int getMarketId() {
		return marketId;
	}
	
	public int getNumberItem(){
		return list.size();
	}
}
